/* http.h : dgnsc http header parser, sip/rtsp can also use
 * Copyright (C) 2009-2011 drangon <drangon.zhou@gmail.com>
 * 2011-09
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_DGNSC_HTTP_H
#define INCLUDED_DGNSC_HTTP_H

#include <dgnsc/str.h>
#include <dgnsc/hashkv.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef struct dgn_http_st * dgn_http_t;
typedef dgn_hashkv_iter_t dgn_http_iter_t;

dgn_http_t dgn_http_init();
dgn_http_t dgn_http_init_parse( const char * str, int * used_len );
void dgn_http_fini( dgn_http_t ht );

// request
const char * dgn_http_get_method( dgn_http_t ht );
const char * dgn_http_get_uri( dgn_http_t ht );
const char * dgn_http_get_request_ver( dgn_http_t ht );

// response
const char * dgn_http_get_response_ver( dgn_http_t ht );
int dgn_http_get_code( dgn_http_t ht );
const char * dgn_http_get_reason( dgn_http_t ht );

// general header
const char * dgn_http_get_header( dgn_http_t ht, const char * key );

// set value
int dgn_http_set_request( dgn_http_t ht, const char * method, const char * uri, const char * ver );
int dgn_http_set_response( dgn_http_t ht, const char * ver, int code, const char * reason );
int dgn_http_set_header( dgn_http_t ht, const char * key, const char * value );
int dgn_http_del_header( dgn_http_t ht, const char * key );

dgn_http_iter_t dgn_http_iter_next( dgn_http_t ht, dgn_http_iter_t iter );
dgn_http_iter_t dgn_http_iter_find( dgn_http_t ht, const char * key );
const char * dgn_http_iter_get_key( dgn_http_t ht, dgn_http_iter_t iter );
const char * dgn_http_iter_get( dgn_http_t ht, dgn_http_iter_t iter );
int dgn_http_iter_set( dgn_http_t ht, dgn_http_iter_t iter, const char * value );
dgn_http_iter_t dgn_http_iter_del( dgn_http_t ht, dgn_http_iter_t iter );

int dgn_http_output( dgn_http_t ht, dgn_str_t buf );

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // INCLUDED_DGNSC_HTTP_H

